#pragma once

#include "TileId.h"
#include "ViewPort.h"
#include "SphereCamera.h"
#include <assert.h>
#include <list>

using namespace std;

namespace VIS
{
	class CVirtualGlobe
	{
		class Tile;
	public:
		CVirtualGlobe(void);
		~CVirtualGlobe(void);

		void drawGlobe();
		void initGlobe();
		void geoCoord(float _normX, float _normY, float &_lon, float &_lat) const;
		void renderTile(const Tile &_tile);
		void updateTiles();
		

		CViewPort* m_ViewPort;
		CSphereCamera* m_camera;
		
		 
	 
	private:
		int num_segments;
		bool m_initLoad;
		double m_left;
		double m_right;
		double m_bottom;
		double m_top;
		double m_near;
		double m_far;
		double m_size;
		double m_modelViewRefer[6];
		double m_horzontalAxis[3];
		double m_verticalAxis[3];
		list<Tile> m_tiles;
	};


	inline void CVirtualGlobe::geoCoord(float _normX, float _normY, float &_lon, float &_lat) const
	{
		assert(0<=_normX && _normX<=1);
		assert(0<=_normY && _normY<=1);
		_lat = (0.5f - _normY) *180.0f;
		_lon = (_normX - 0.5f) *360.0f;
	}

	class CVirtualGlobe::Tile
	{
	public:
		Tile(const TileId &id, GLuint glName);
		TileId id() const { return m_id;}
		GLuint glName() const{ return m_glName;}
		bool operator==(const Tile &other);

	private:
		TileId m_id;
		GLuint m_glName;
	};
}
